package dreamCookGame.chickenMiniGame;

public class BearEntity extends Entity {
	boolean _movingRight;
	boolean _movingUp;
	boolean _movingDown;
	boolean _movingLeft;

	
	public BearEntity(String name, String[] nameArray) {
		super(name, nameArray);
	}
	public BearEntity(String name, String[] nameArray, Vector location) {
		super(name, nameArray);
		this.setLocation(location);
	}
	public BearEntity(String name, String[] nameArray, float x, float y) {
		super(name, nameArray);
		this.setLocation(x,y);
		setInitialVariables();
	}
	private void setInitialVariables(){
		this.setHorizontalVelocity(0);
		this.setVerticalVelocity(0);
		this.setAccelerationRate(3);
		this.setFriction(2f);
		this.setMaxSpeed(20);
	}
	
	public void update(){

		if(_movingLeft){
			this.setHorizontalVelocity(this._horizontalVelocity-this._accelerationRate);
		}
		if(_movingRight){
			this.setHorizontalVelocity(this._horizontalVelocity+this._accelerationRate);
		}
		if(_movingUp){
			this.setVerticalVelocity(this._verticalVelocity-this._accelerationRate);
		}
		if(_movingDown){
			this.setVerticalVelocity(this._verticalVelocity+this._accelerationRate);
		}
		if(this._location.getX()>=800){
			if(this._velocity.getX()>0){
				this.setHorizontalVelocity(0);
			}
		}else if(this._location.getX()<=0){
			if(this._velocity.getX()<0){
				this.setHorizontalVelocity(0);
			}
		}
		if(this._location.getY()>=600){
			if(this._velocity.getY()>0){
				this.setVerticalVelocity(0);
			}
		}else if(this._location.getY()<=0){
			if(this._velocity.getY()<0){
				this.setVerticalVelocity(0);
			}
		}
		
		super.update();
	}

	public void setInMotion(char direction) {
		switch(direction) {
			case 'r':
				_movingRight = true;
				break;
			case 'l':
				_movingLeft = true;
				break;
			case 'u':
				_movingUp = true;
				break;
			case 'd':
				_movingDown = true;
				break;
		}
	}
	public void stopMotion(char direction) {
		switch(direction) {
		case 'r':
			_movingRight = false;
			break;
		case 'l':
			_movingLeft = false;
			break;
		case 'u':
			_movingUp = false;
			break;
		case 'd':
			_movingDown = false;
			break;
		}
	}
}
